package com.wn.web;

import com.wn.common.annotation.RequireRoles;
import com.wn.common.pojo.PageParam;
import com.wn.common.pojo.Role;
import com.wn.common.pojo.Rsp;
import com.wn.service.RoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestControllerAdvice
@RequestMapping("role")
@Api(value="角色接口",description = "角色接口")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("add_role")
    @RequireRoles(roles = "super_admin",index = 0,type=Role.class)
    public Rsp addRole(@RequestHeader("token") String token, @RequestBody  Role role){
        return roleService.insertRole(role);
    }

    @PostMapping("update_role")
    @RequireRoles(roles = "super_admin",index = 1,type = Role.class)
    public Rsp updateRole( @RequestBody  Role role,@RequestHeader("token") String token){
        return roleService.updateRole(role);
    }

    @PostMapping("delete_role")
    @RequireRoles(roles = "super_admin",index = 1,type=Role.class)
    public Rsp deleteRole( @RequestBody  Role role,@RequestHeader("token") String token){
        return roleService.deleteRole(role);
    }

    @PostMapping("query_role_list")
    @RequireRoles(roles = "super_admin",index = 0,type=Role.class)
    public Rsp queryRoleList(@RequestHeader("token") String token,@RequestBody PageParam<Role> pageParam){
        return roleService.getRoleList(pageParam);
    }

    @PostMapping("query_role_by_id")
    @RequireRoles(roles = "super_admin",index = 0,type=Role.class)
    public Rsp queryRoleById(@RequestHeader("token") String token, Role role){
        return roleService.getRoleByPrimaryKey(role.getRoleId());
    }

    @PostMapping("update_status")
    @RequireRoles(roles = "super_admin",index = 1,type=Role.class)
    public Rsp updateStatus(@RequestBody Role role,@RequestHeader("token")String token){
        return roleService.updateStatus(role);
    }


}
